10 + 20
// Access object properies with .
// Access string and array elements with []
let data := {
numbers := [1, 2, 3],
chars := ["a", "b", "c"],
string := "Albert"
};
write!(data.numbers[0]);
write!(data.chars[2]);
write!(data.string[0]);
write!({a := 1, b := 2, c := 3}.b);
write!("Albert"[3]);
write!([1, 2, 3][2]);
plus(x, y)
// Functional Text Adventure Game in Lits
// Define locations
let locations := {
forest := {
description := "You are in a dense forest. Light filters through the leaves above.",
exits := { north := "cave", east := "river", south := "meadow" }
},
cave := {
description := "You stand in a dark cave. Water drips from stalactites overhead.",
exits := { south := "forest", east := "tunnel" },
items := ["torch"]
},
river := {
description := "A swift river flows from the mountains. The water is crystal clear.",
exits := { west := "forest", north := "waterfall" },
items := ["fishing rod"]
},
meadow := {
description := "A peaceful meadow stretches before you, filled with wildflowers.",
exits := { north := "forest", east := "cottage" },
items := ["flowers"]
},
waterfall := {
description := "A magnificent waterfall cascades down from high cliffs.",
exits := { south := "river" },
items := ["shiny stone"]
},
tunnel := {
description := "A narrow tunnel leads deeper into the mountain.",
exits := { west := "cave", east := "treasure room" }
},
"treasure room" := {
description := "A small chamber glittering with treasure!",
exits := { west := "tunnel" },
items := ["gold key", "ancient map", "jeweled crown"]
},
cottage := {
description := "A cozy cottage with a smoking chimney stands here.",
exits := { west := "meadow" },
items := ["bread"]
}
};
// Define game state
let initial-state := {
current-location := "forest",
inventory := [],
visited := {},
game-over := false,
moves := 0,
light-source := false
};
// Helper functions
function has-item?(state, item)
contains?(state.inventory, item);
end;
function location-has-item?(location, item)
contains?(get(location, "items", []), item);
end;
function describe-location(state)
let location := get(locations, state.current-location);
let description := location.description;
// Add visited status
let visited-status := if get(state.visited, state.current-location, 0) > 1 then
"You've been here before."
else
"This is your first time here."
end;
// Check if location has items
let items-desc := if !(empty?(get(location, "items", []))) then
"You see: " ++ join(location.items, ", ")
end;
// Describe exits
let exits := keys(location.exits) join ", ";
let exits-desc := "Exits: " ++ exits;
// Join all descriptions
filter([description, visited-status, items-desc, exits-desc], -> !(empty?($))) join "\n"
end;
function get-location-items(state)
let location := get(locations, state.current-location);
get(location, "items", [])
end;
// Game actions
function move(state, direction)
let location := get(locations, state.current-location);
let exits := get(location, "exits", {});
// Check if direction is valid
if contains?(exits, direction) then
let new-location := get(exits, direction);
let is-dark := new-location = "tunnel" || new-location = "treasure room";
// Check if player has light source for dark areas
if is-dark && !(state.light-source) then
[state, "It's too dark to go that way without a light source."]
else
let new-visited := assoc(
state.visited,
new-location,
inc(state.visited["new-location"] ?? 0)
);
let new-state := assoc(
assoc(
assoc(state, "current-location", new-location),
"visited",
new-visited
),
"moves",
state.moves + 1
);
[new-state, "You move " ++ direction ++ " to the " ++ new-location ++ "."]
end
else
[state, "You can't go that way."]
end
end;
function take!(state, item)
let items := get-location-items(state);
if contains?(items, item) then
let location := get(locations, state.current-location);
let new-location-items := filter(items, -> $ ≠ item);
let new-inventory := push(state.inventory, item);
// Update game state
let new-locations := assoc(
locations,
state.current-location,
assoc(location, "items", new-location-items)
);
// Special case for torch
let has-light := item = "torch" || state.light-source;
// Update locations and state
let locations := new-locations;
let new-state := assoc(
assoc(
assoc(state, "inventory", new-inventory),
"light-source", has-light
),
"moves",
state.moves + 1
);
[new-state, "You take the " ++ item ++ "."]
else
[state, "There is no " ++ item ++ " here."]
end
end;
function drop!(state, item)
if has-item?(state, item) then
let location := get(locations, state.current-location);
let location-items := get(location, "items", []);
let new-location-items := push(location-items, item);
let new-inventory := filter(-> $ ≠ item, state.inventory);
// Special case for torch
let still-has-light := !(item = "torch") || contains?(new-inventory, "torch");
// Update locations and state
let new-location := assoc(location, "items", new-location-items);
let locations := assoc(locations, state.current-location, new-location);
let new-state := assoc(
assoc(
assoc(
state, "inventory", new-inventory),
"light-source",
still-has-light
),
"moves",
state.moves + 1
);
[new-state, "You drop the " ++ item ++ "."]
else
[state, "You don't have a " ++ item ++ " in your inventory."]
end
end;
function inventory(state)
if empty?(state.inventory) then
[state, "Your inventory is empty."]
else
[state, "Inventory: " ++ join(state.inventory, ", ")]
end
end;
function use(state, item)
switch item
case "fishing rod" then
if state.current-location = "river" then
[assoc(state, "moves", state.moves + 1), "You catch a small fish, but it slips away."]
else
[state, "There's no place to use a fishing rod here."]
end
case "torch" then
if has-item?(state, item) then
[
assoc(assoc(state, "light-source", true), "moves", state.moves + 1),
"The torch illuminates the area with a warm glow."
]
else
[state, "You don't have a torch."]
end
case "gold key" then
if has-item?(state, item) && state.current-location = "treasure room" then
[
assoc(
assoc(state, "game-over", true),
"moves",
state.moves + 1
),
"You use the gold key to unlock a secret compartment, revealing a fabulous diamond! You win!"
]
else
[state, "The key doesn't fit anything here."]
end
case "bread" then
if has-item?(state, item) then
let new-inventory := filter(state.inventory, -> $ ≠ item);
[
assoc(
assoc(state, "inventory", new-inventory),
"moves",
state.moves + 1
),
"You eat the bread. It's delicious and nourishing."
]
else
[state, "You don't have any bread."]
end
case "shiny stone" then
if has-item?(state, item) then
[
assoc(state, "moves", state.moves + 1),
"The stone glows with a faint blue light. It seems magical but you're not sure how to use it yet."
]
else
[state, "You don't have a shiny stone."]
end
case "flowers" then
if has-item?(state, item) then
[
assoc(state, "moves", state.moves + 1),
"You smell the flowers. They have a sweet, calming fragrance."
]
else
[state, "You don't have any flowers."]
end
case "ancient map" then
if has-item?(state, item) then
[
assoc(state, "moves", state.moves + 1),
"The map shows the layout of the area. All locations are now marked as visited."
]
else
[state, "You don't have a map."]
end
case "jeweled crown" then
if has-item?(state, item) then
[
assoc(state, "moves", state.moves + 1),
"You place the crown on your head. You feel very regal."
]
else
[state, "You don't have a crown."]
end
end ?? [state, "You can't use that."]
end;
// Command parser
function parse-command(state, input)
let tokens := lower-case(input) split " ";
let command := first(tokens);
let args := rest(tokens) join " ";
let result := switch command
case "go" then
move(state, args)
case "north" then
move(state, "north")
case "south" then
move(state, "south")
case "east" then
move(state, "east")
case "west" then
move(state, "west")
case "take" then
take!(state, args)
case "drop" then
drop!(state, args)
case "inventory" then
inventory(state)
case "i" then
inventory(state)
case "look" then
[assoc(state, "moves", state.moves + 1), describe-location(state)]
case "use" then
use(state, args)
case "help" then
[state, "Commands: go [direction], north, south, east, west, take [item], drop [item], inventory, look, use [item], help, quit"]
case "quit" then
[assoc(state, "game-over", true), "Thanks for playing!"]
end ?? [state, "I don't understand that command. Type 'help' for a list of commands."];
result
end;
// Game loop
function game-loop(state)
alert!(describe-location(state) ++ "\nWhat do you do? ");
let input := read-line!();
let command_result := parse-command(state, input);
let new-state := first(command_result);
let message := second(command_result);
alert!("\n" ++ message ++ "\n");
if new-state.game-over then
alert!("\nGame over! You made " ++ str(new-state.moves) ++ " moves.");
new-state
else
game-loop(new-state)
end
end;
// Start game
function start-game()
alert!("=== Lits Adventure Game ===\n" ++ "Type 'help' for a list of commands.\n\n");
game-loop(initial-state)
end;
// Call the function to start the game
start-game()
// Determinant function for square matrices
function determinant(matrix)
// Check if input is an array
unless array?(matrix) then
throw("Input must be an array");
end;
// Check if matrix is empty
if empty?(matrix) then
throw("Matrix cannot be empty");
end;
let rows := count(matrix);
// Get first row to check column count
let firstRow := first(matrix);
// Check if first row is an array
unless array?(firstRow) then
throw("Input must be a 2D array");
end;
let cols := count(firstRow);
// Ensure matrix is square
if rows ≠ cols then
throw("Matrix must be square");
end;
// Base case: 1x1 matrix
if rows = 1 then
matrix[0][0];
else
// Base case: 2x2 matrix
if rows = 2 then
let a := matrix[0][0];
let b := matrix[0][1];
let c := matrix[1][0];
let d := matrix[1][1];
a * d - b * c;
else
// For larger matrices, use cofactor expansion along first row
// Use reduce to calculate the determinant without mutating variables
reduce(
range(cols),
(acc, j) -> do
let minor := getMinor(matrix, 0, j);
let cofactor := determinant(minor);
let signFactor := if even?(j) then 1 else -1 end;
let term := signFactor * matrix[0][j] * cofactor;
acc + term;
end,
0,
);
end;
end;
end;
// Helper function to get minor (submatrix) by removing specific row and column
function getMinor(matrix, rowToRemove, colToRemove)
// Use map with filter to create the new matrix without mutating
map(
range(count(matrix)),
i -> do
if i = rowToRemove then
null; // This will be filtered out
else
let row := get(matrix, i);
// Filter out the column to remove
map(
range(count(row)),
j -> do
if j = colToRemove then null else get(row, j) end;
end
) filter (item -> item ≠ null);
end;
end
) filter (row -> row ≠ null);
end;
// 4x4 invertible matrix
let matrix4x4 := [
[4, 3, 2, 2],
[0, 1, -3, 3],
[0, -1, 3, 3],
[0, 3, 1, 1]
];
determinant(matrix4x4);
// Matrix multiplication with correct syntax
function matrixMultiply(matrixA, matrixB)
// Check if inputs are arrays
unless array?(matrixA) then throw("First input must be an array") end;
unless array?(matrixB) then throw("Second input must be an array") end;
// Check if matrices are not empty
if empty?(matrixA) || empty?(matrixB) then throw("Matrices cannot be empty") end;
// Check if matrices are 2D arrays
unless array?(first(matrixA)) then throw("First input must be a 2D array") end;
unless array?(first(matrixB)) then throw("Second input must be a 2D array") end;
// Get dimensions
let rowsA := count(matrixA);
let colsA := count(first(matrixA));
let rowsB := count(matrixB);
let colsB := count(first(matrixB));
// Check if all rows have consistent length
unless every?(matrixA, row -> array?(row) && count(row) = colsA) then
throw("First matrix has inconsistent row lengths")
end;
unless every?(matrixB, row -> array?(row) && count(row) = colsB) then
throw("Second matrix has inconsistent row lengths")
end;
// Check if matrices can be multiplied
unless colsA = rowsB then
throw("Matrix dimensions mismatch: first matrix columns must equal second matrix rows");
end;
// Create a row of the result matrix
function createRow(rowIndex)
for each j in range(colsB) do
reduce(
range(colsA),
(sum, k) -> do
let aValue := matrixA[rowIndex][k];
let bValue := matrixB[k][j];
sum + (aValue * bValue);
end,
0
)
end
end;
// Create the result matrix row by row
for each i in range(rowsA) do
createRow(i);
end;
end;
let matrixA := [
[1, 2, 3],
[4, 5, 6]
];
let matrixB := [
[7, 8],
[9, 10],
[11, 12]
];
matrixMultiply(matrixA, matrixB);
function formatPhoneNumber(data)
if string?(data) then
let phoneNumber :=
if data[0] = "+" then
data slice 2
else
data
end;
let length := count(phoneNumber);
cond
case length > 6 then
"(" ++ slice(phoneNumber, 0, 3) ++ ") " ++ slice(phoneNumber, 3, 6) ++ "-" ++ slice(phoneNumber, 6)
case length > 3 then
"(" ++ slice(phoneNumber, 0, 3) ++ ") " ++ slice(phoneNumber, 3)
case length > 0 then
"(" ++ slice(phoneNumber, 0)
end ?? ""
else
""
end
end;
write!(formatPhoneNumber);
write!(formatPhoneNumber(123234));
write!(formatPhoneNumber("123234"));
write!(formatPhoneNumber("1232343456"));
write!(formatPhoneNumber("+11232343456789"));
write!(formatPhoneNumber("+11232343456"));
function factorial(x)
if x = 1 then
1
else
x * factorial(x - 1)
end
end;
factorial(5)
let l := [7, 39, 45, 0, 23, 1, 50, 100, 12, -5];
function numberComparer(a, b)
cond
case a < b then -1
case a > b then 1
end ?? 0
end;
sort(l, numberComparer)
function isoDateString?(data)
let m := data match #"^(\d{4})-(\d{2})-(\d{2})$";
if m then
let [year, month, day] := slice(m, 1) map number;
let leapYear := zero?(year mod 4) && (!zero?(year mod 100) || zero?(year mod 400));
let invalid :=
(year < 1900 || year > 2100)
|| (month < 1 || month > 12)
|| (day < 1 || day > 31)
|| day > 30 && (month = 4 || month = 6 || month = 9 || month = 11)
|| month = 2 && (leapYear && day > 29 || !leapYear && day > 28);
!(invalid)
else
false
end
end;
write!(isoDateString?("1978-12-21"));
write!(isoDateString?("197-12-21"));
function label-from-value(items, value)
let entry := items some (-> value = $["value"]);
if entry = null then
null
else
entry["label"]
end
end;
let items := [
{ label := "Name", value := "name" },
{ label := "Age", value := "age" }
];
label-from-value(items, "name");
function labels-from-values($array, $values)
for
each value in $values,
let label := do
let entry := $array some -> value = $["value"];
if entry = null then
value
else
entry["label"]
end
end
do
label
end
end;
let arr := [
{ label := "Name", value := "name" },
{ label := "Age", value := "age" },
{ label := "Email", value := "email" },
];
labels-from-values(arr, ["name", "age"])
| count(coll) | → | number |
| coll | collection | null |
| a | collection | |
| b | string | integer | |
| not-found | any |
Default value to return if b is not found.
|
| a | collection |
| b | array |
| not-found | any |
| a | collection | null |
| b | string | integer |
| assoc(coll, key, value) | → | collection |
| assoc(coll, key, value, ...kvs) | → | collection |
If coll is an 'array', key must be number satisfying 0 <= key <= length.
| coll | collection | |
| key | string | number | |
| value | any | |
| kvs | Array<any> |
Key-value pairs to associate.
|
| assoc-in(coll, ks, value) | → | collection |
If any levels do not exist, objects will be created - and the corresponding keys must be of type string.
| coll | collection |
| ks | Array<number | string> |
| value | any |
| a ++ b | → | collection |
| ++(a) | → | collection |
| ++(a, ...colls) | → | collection |
| a concat b | → | collection |
| concat(a) | → | collection |
| concat(a, ...colls) | → | collection |
| a | collection |
| b | collection |
| colls | Array<collection> |
| not-empty(coll) | → | boolean |
| coll | collection | null |
| a | collection |
| b | function |
| a | collection |
| b | function |
| a | collection |
| b | function |
| a | collection |
| b | function |
| update(coll, , fun) | → | collection |
| update(coll, , fun, ...fun-args) | → | collection |
| coll | collection |
| key | string | number |
| fun | function |
| fun-args | Array<any> |
| update-in(coll, ks, fun) | → | collection |
| update-in(coll, ks, fun, ...fun-args) | → | collection |
| coll | collection |
| ks | array |
| fun | function |
| fun-args | Array<any> |
| a range b | → | Array<number> |
| range(b) | → | Array<number> |
| range(a, b) | → | Array<number> |
| range(a, b, step) | → | Array<number> |
a defaults to 0.
step defaults to 1.
| flatten(x) | → | Array<any> |
| a mapcat b | → | collection |
| mapcat(colls, fun) | → | collection |
| a | collection |
| b | function |
| colls | Array<collection> |
| fun | function |
| seq | sequence |
| seq | sequence |
| a slice b | → | sequence |
| slice(...seq) | → | sequence |
| slice(...seq, start) | → | sequence |
| slice(...seq, start, stop) | → | sequence |
| a | sequence | |
| b | integer | |
| seq | Array<sequence> | |
| start | integer |
Defaults to 0.
|
| stop | integer |
Defaults lenght of sequence + 1.
|
| splice(...seq, start, deleteCount) | → | sequence |
| splice(...seq, start, deleteCount, ...items) | → | sequence |
| a reductions b | → | Array<any> |
| reductions(...seq, fun) | → | Array<any> |
| reductions(...seq, fun, start) | → | Array<any> |
| a reduce-right b | → | sequence |
| reduce-right(seq, fun) | → | sequence |
| reduce-right(seq, fun, start) | → | sequence |
| first(seq) | → | any |
| second(seq) | → | any |
| last(seq) | → | any |
| seq | sequence |
| seq | sequence |
| a sort-by b | → | Array<any> |
| sort-by(seq, keyfn) | → | Array<any> |
| sort-by(seq, keyfn, comparer) | → | Array<any> |
| distinct(seq) | → | sequence |
| seq | sequence |
| frequencies(seq) | → | object |
| seq | sequence |
| a partition b | → | sequence |
| partition(seq, n) | → | sequence |
| partition(seq, n, step) | → | sequence |
| partition(seq, n, step, pad) | → | sequence |
| a partition-all b | → | sequence |
| partition-all(seq, n) | → | sequence |
| partition-all(seq, n, step) | → | sequence |
| inc(x) | → | number |
| x | number |
| dec(x) | → | number |
| x | number |
| x | number |
| x | number |
| trunc(x) | → | integer |
| x | number |
| floor(x) | → | integer |
| x | number |
| ceil(x) | → | integer |
| x | number |
| abs(x) | → | number |
| x | number |
| sign(x) | → | number |
| x | number |
| log(x) | → | number |
| x | number |
| x | number |
| x | number |
| sin(x) | → | number |
| x | number |
| cos(x) | → | number |
| x | number |
| tan(x) | → | number |
| x | number |
| asin(x) | → | number |
| x | number |
| acos(x) | → | number |
| x | number |
| atan(x) | → | number |
| x | number |
| sinh(x) | → | number |
| x | number |
| cosh(x) | → | number |
| x | number |
| tanh(x) | → | number |
| x | number |
| asinh(x) | → | number |
| x | number |
| acosh(x) | → | number |
| x | number |
| atanh(x) | → | number |
| x | number |
| identity(x) | → | any |
| x | any |
| partial(fun, ...args) | → | function |
The returned function takes a variable number of arguments, applies the rightmost function to the args, the next function (right-to-left) to the result, etc.
| constantly(x) | → | function |
| x | any |
The returned function takes a variable number of args, and returns a vector containing the result of applying each function to the args (left-to-right).
| complement(fun) | → | function |
| fun | function |
| a ≠ b | → | boolean |
| ≠(x) | → | boolean |
| ≠(x, ...ys) | → | boolean |
| a != b | → | boolean |
| !=(x) | → | boolean |
| !=(x, ...ys) | → | boolean |
| a ≤ b | → | boolean |
| ≤(x) | → | boolean |
| ≤(x, ...ys) | → | boolean |
| a <= b | → | boolean |
| <=(x) | → | boolean |
| <=(x, ...ys) | → | boolean |
| a ≥ b | → | boolean |
| ≥(x) | → | boolean |
| ≥(x, ...ys) | → | boolean |
| a >= b | → | boolean |
| >=(x) | → | boolean |
| >=(x, ...ys) | → | boolean |
| !(x) | → | boolean |
| x | any |
| write!(...values) | → | any |
| values | Array<any> |
| iso-date->epoch(iso) | → | number |
| iso | string |
| epoch->iso-date(ms) | → | string |
| ms | number |
| boolean(x) | → | boolean |
| x | any |
| json-parse(x) | → | any |
| x | string |
| keys(obj) | → | Array<any> |
| obj | object |
| vals(obj) | → | Array<any> |
| obj | object |
| entries(obj) | → | array |
| obj | object |
If two keys appears in more than one object the value from the last object is used.
If no arguments are provided null is returned.
| merge-with(...objs, fun) | → | object |
If no arguments are provided null is returned.
| boolean?(x) | → | boolean |
| x | any |
| null?(x) | → | boolean |
| x | any |
| number?(x) | → | boolean |
| x | any |
| string?(x) | → | boolean |
| x | any |
| function?(x) | → | boolean |
| x | any |
| integer?(x) | → | boolean |
| x | any |
| array?(x) | → | boolean |
| x | any |
| object?(x) | → | boolean |
| x | any |
| coll?(x) | → | boolean |
| x | any |
| seq?(x) | → | boolean |
| x | any |
| regexp?(x) | → | boolean |
| x | any |
| zero?(x) | → | boolean |
| x | number |
| pos?(x) | → | boolean |
| x | number |
| neg?(x) | → | boolean |
| x | number |
| even?(x) | → | boolean |
| x | number |
| odd?(x) | → | boolean |
| x | number |
| finite?(x) | → | boolean |
| x | number |
| nan?(x) | → | boolean |
| x | number |
| negative-infinity?(x) | → | boolean |
| x | number |
| positive-infinity?(x) | → | boolean |
| x | number |
| false?(x) | → | boolean |
| x | any |
| true?(x) | → | boolean |
| x | any |
| empty?(x) | → | boolean |
| x | collection | string | null |
| not-empty?(x) | → | boolean |
| x | collection | string | null |
| pattern | string | |
| flags | string |
Optional flags for the regular expression. Possible values are the same as Javascript RegExp takes.
|
| replace(a, b, x) | → | Array<any> |
| replace-all(a, b, x) | → | Array<any> |
| str(...values) | → | string |
| values | Array<any> |
| number(s) | → | number |
| s | string |
| lower-case(s) | → | string |
| s | string |
| upper-case(s) | → | string |
| s | string |
| trim(s) | → | string |
| s | string |
| trim-left(s) | → | string |
| s | string |
| trim-right(s) | → | string |
| s | string |
| split-lines(s) | → | string |
| s | string |
| template(s, ...params) | → | string |
| to-char-code(c) | → | number |
| c | string |
| from-char-code(code) | → | string |
| code | number |
| encode-base64(s) | → | string |
| s | string |
| decode-base64(base64string) | → | string |
| base64string | string |
| encode-uri-component(s) | → | string |
| s | string |
| decode-uri-component(s) | → | string |
| s | string |
| capitalize(s) | → | string |
| s | string |
| blank?(s) | → | boolean |
| ~(a) | → | integer |
| a | integer |
| matrix?(value) | → | boolean |
| value | any |
| nth:abundant-seq(length) | → | Array<integer> |
| length | integer |
The length of the sequence to generate.
|
| nth:abundant-take-while(takeWhile) | → | Array<integer> |
| takeWhile | function |
A function that takes an integer and an index and returns a boolean.
|
| nth:abundant-nth(n) | → | integer |
| n | integer |
The index of the number in the sequence.
|
| nth:abundant?(n) | → | boolean |
| n | integer |
The number to check.
|
| nth:arithmetic-seq(start, step, length) | → | Array<integer> |
| start | number |
The starting term of the sequence.
|
| step | number |
The common difference of the sequence.
|
| length | integer |
The length of the sequence to generate.
|
| nth:arithmetic-take-while(start, step, takeWhile) | → | Array<integer> |
| start | number |
The starting term of the sequence.
|
| step | number |
The common difference of the sequence.
|
| takeWhile | function |
A function that takes a number and an index and returns a boolean.
|
| nth:arithmetic-nth(start, step, n) | → | integer |
| start | number |
The starting term of the sequence.
|
| step | number |
The common difference of the sequence.
|
| n | integer |
The index of the term to generate.
|
| nth:arithmetic?(start, step, n) | → | boolean |
| start | number |
The starting term of the sequence.
|
| step | number |
The common difference of the sequence.
|
| n | integer |
The number to check.
|
| length | integer |
The length of the sequence to generate. If not provided, the default is 22 (the maximum length of the pre-calculated bell numbers).
|
| nth:bell-take-while(takeWhile) | → | Array<integer> |
| takeWhile | function |
A function that takes an integer and an index and returns a boolean.
|
| nth:bell-nth(n) | → | integer |
| n | integer |
The index of the term to generate.
|
| nth:bell?(n) | → | boolean |
| n | integer |
The number to check.
|
| nth:bernoulli-seq(length) | → | Array<number> |
| length | integer |
The length of the sequence to generate.
|
| nth:bernoulli-take-while(takeWhile) | → | Array<number> |
| takeWhile | function |
A function that takes an integer and an index and returns a boolean.
|
| nth:bernoulli-nth(n) | → | number |
| n | integer |
The index of the term to generate.
|
| length | integer |
The length of the sequence to generate. If not provided, the default is 30 (the maximum length of the pre-calculated catalan numbers).
|
| nth:catalan-take-while(takeWhile) | → | Array<integer> |
| takeWhile | function |
A function that takes an integer and an index and returns a boolean.
|
| nth:catalan-nth(n) | → | integer |
| n | integer |
The index of the term to generate.
|
| nth:catalan?(n) | → | boolean |
| n | integer |
The number to check.
|
| nth:collatz-seq(start) | → | Array<integer> |
| start | integer |
The starting integer for the collatz sequence.
|
| nth:composite-seq(length) | → | Array<integer> |
| length | integer |
The length of the sequence to generate.
|
| nth:composite-take-while(takeWhile) | → | Array<integer> |
| takeWhile | function |
A function that takes an integer and an index and returns a boolean.
|
| nth:composite-nth(n) | → | integer |
| n | integer |
The index of the composite number to retrieve.
|
| nth:composite?(n) | → | boolean |
| n | integer |
The number to check.
|
| length | integer |
The length of the sequence to generate. If not provided, the default is 19 (the maximum length of the pre-calculated factorial numbers).
|
| nth:factorial-take-while(takeWhile) | → | Array<integer> |
| takeWhile | function |
A function that takes an integer and an index and returns a boolean.
|
| nth:factorial-nth(n) | → | integer |
| n | integer |
The index of the term to generate.
|
| nth:factorial?(n) | → | boolean |
| n | integer |
The number to check.
|
| length | integer |
The length of the sequence to generate. If not provided, the default is 79 (the maximum length of the pre-calculated Fibonacci numbers).
|
| nth:fibonacci-take-while(takeWhile) | → | Array<integer> |
| takeWhile | function |
A function that takes an integer and an index and returns a boolean.
|
| nth:fibonacci-nth(n) | → | integer |
| n | integer |
The index of the term to generate.
|
| nth:fibonacci?(n) | → | boolean |
| n | integer |
The number to check.
|
| nth:geometric-seq(start, ratio, length) | → | Array<integer> |
| start | number |
The starting term of the sequence.
|
| ratio | number |
The common ratio of the sequence.
|
| length | integer |
The length of the sequence to generate.
|
| nth:geometric-take-while(start, ratio, takeWhile) | → | Array<integer> |
| start | number |
The starting term of the sequence.
|
| ratio | number |
The common ratio of the sequence.
|
| takeWhile | function |
A function that takes a number and an index and returns a boolean.
|
| nth:geometric-nth(start, ratio, n) | → | integer |
| start | number |
The starting term of the sequence.
|
| ratio | number |
The common ratio of the sequence.
|
| n | integer |
The index of the term to generate.
|
| nth:geometric?(start, ratio, number) | → | boolean |
| start | number |
The starting term of the sequence.
|
| ratio | number |
The common ratio of the sequence.
|
| number | number |
The number to check.
|
| nth:golomb-seq(length) | → | Array<integer> |
| length | integer |
The length of the sequence to generate.
|
| nth:golomb-take-while(takeWhile) | → | Array<integer> |
| takeWhile | function |
A function that takes an integer and an index and returns a boolean.
|
| nth:golomb-nth(n) | → | integer |
| n | integer |
The index of the term to generate.
|
| nth:golomb?(n) | → | boolean |
| n | integer |
The number to check.
|
| length | integer |
The length of the sequence to generate. If not provided, the default is 20 (the maximum length of the pre-calculated happy numbers).
|
| nth:happy-take-while(takeWhile) | → | Array<integer> |
| takeWhile | function |
A function that takes an integer and an index and returns a boolean.
|
| nth:happy-nth(n) | → | integer |
| n | integer |
The index of the happy number to return.
|
| nth:happy?(n) | → | boolean |
| n | integer |
The number to check.
|
| nth:juggler-seq(start) | → | Array<integer> |
| start | integer |
The starting integer for the Juggler sequence.
|
| nth:look-and-say-seq(length) | → | Array<string> |
| length | integer |
The length of the sequence to generate.
|
| nth:look-and-say-take-while(takeWhile) | → | Array<string> |
| takeWhile | function |
A function that takes a string and an index and returns a boolean.
|
| nth:look-and-say-nth(n) | → | string |
| n | integer |
The index of the term in the sequence.
|
| nth:look-and-say?(term) | → | boolean |
| term | string |
The term to check.
|
| length | integer |
The length of the sequence to generate. If not provided, the default is 77 (the maximum length of the pre-calculated Lucas numbers).
|
| nth:lucas-take-while(takeWhile) | → | Array<integer> |
| takeWhile | function |
A function that takes an integer and an index and returns a boolean.
|
| nth:lucas-nth(n) | → | integer |
| n | integer |
The index of the term to generate.
|
| nth:lucas?(n) | → | boolean |
| n | integer |
The number to check.
|
| nth:lucky-seq(length) | → | Array<integer> |
| length | integer |
The length of the sequence to generate.
|
| nth:lucky-take-while(takeWhile) | → | Array<integer> |
| takeWhile | function |
A function that takes an integer and an index and returns a boolean.
|
| nth:lucky-nth(n) | → | integer |
| n | integer |
The position in the sequence.
|
| nth:lucky?(n) | → | boolean |
| n | integer |
The number to check.
|
| length | integer |
The length of the sequence to generate. If not provided, the default is 9 (the maximum length of the pre-calculated mersenne numbers).
|
| nth:mersenne-take-while(takeWhile) | → | Array<integer> |
| takeWhile | function |
A function that takes an integer and an index and returns a boolean.
|
| nth:mersenne-nth(n) | → | integer |
| n | integer |
The index of the term to generate.
|
| nth:mersenne?(n) | → | boolean |
| n | integer |
The number to check.
|
| nth:padovan-seq(length) | → | Array<integer> |
| length | integer |
The length of the sequence to generate.
|
| nth:padovan-take-while(takeWhile) | → | Array<integer> |
| takeWhile | function |
A function that takes an integer and an index and returns a boolean.
|
| nth:padovan-nth(n) | → | integer |
| n | integer |
The index of the term to generate.
|
| nth:padovan?(n) | → | boolean |
| n | integer |
The number to check.
|
| length | integer |
The length of the sequence to generate.
|
| nth:partition-take-while(takeWhile) | → | Array<integer> |
| takeWhile | function |
A function that takes an integer and an index and returns a boolean.
|
| nth:partition-nth(n) | → | integer |
| n | integer |
The index of the partition number to generate.
|
| nth:partition?(n) | → | boolean |
| n | integer |
The number to check.
|
| length | integer |
The length of the sequence to generate. If not provided, the default is 42 (the maximum length of the pre-calculated Pell numbers).
|
| nth:pell-take-while(takeWhile) | → | Array<integer> |
| takeWhile | function |
A function that takes an integer and an index and returns a boolean.
|
| nth:pell-nth(n) | → | integer |
| n | integer |
The index of the term to generate.
|
| nth:pell?(n) | → | boolean |
| n | integer |
The number to check.
|
| length | integer |
The length of the sequence to generate. If no length is provided, it defaults to 7 (the maximum length of the pre-calculated perfect numbers).
|
| nth:perfect-take-while(takeWhile) | → | Array<integer> |
| takeWhile | function |
A function that takes an integer and an index and returns a boolean.
|
| nth:perfect-nth(n) | → | integer |
| n | integer |
The index of the perfect number to generate.
|
| nth:perfect?(n) | → | boolean |
| n | integer |
The number to check.
|
| nth:perfect-square-seq(length) | → | Array<integer> |
| length | integer |
The length of the sequence to generate.
|
| nth:perfect-square-take-while(takeWhile) | → | Array<integer> |
| takeWhile | function |
A function that takes an integer and an index and returns a boolean.
|
| nth:perfect-square-nth(n) | → | integer |
| n | integer |
The index of the term to generate.
|
| nth:perfect-square?(n) | → | boolean |
| n | integer |
The number to check.
|
| nth:perfect-cube-seq(length) | → | Array<integer> |
| length | integer |
The length of the sequence to generate.
|
| nth:perfect-cube-take-while(takeWhile) | → | Array<integer> |
| takeWhile | function |
A function that takes an integer and an index and returns a boolean.
|
| nth:perfect-cube-nth(n) | → | integer |
| n | integer |
The index of the term to generate.
|
| nth:perfect-cube?(n) | → | boolean |
| n | integer |
The number to check.
|
| nth:perfect-power-seq(length) | → | Array<integer> |
| length | integer |
The length of the sequence to generate.
|
| nth:perfect-power-take-while(takeWhile) | → | Array<integer> |
| takeWhile | function |
A function that takes an integer and an index and returns a boolean.
|
| nth:perfect-power-nth(n) | → | integer |
| n | integer |
The index of the term to generate.
|
| nth:perfect-power?(n) | → | boolean |
| n | integer |
The number to check.
|
| sides | integer |
The number of sides of the polygon.
|
| length | integer |
The length of the sequence to generate.
|
| a nth:polygonal-take-while b | → | Array<integer> |
| nth:polygonal-take-while(sides, takeWhile) | → | Array<integer> |
| sides | integer |
The number of sides of the polygon.
|
| takeWhile | function |
A function that takes an integer and an index and returns a boolean.
|
| sides | integer |
The number of sides of the polygon.
|
| n | integer |
The index of the term to generate.
|
| nth:prime-seq(length) | → | Array<integer> |
| length | integer |
The length of the sequence to generate.
|
| nth:prime-take-while(takeWhile) | → | Array<integer> |
| takeWhile | function |
A function that takes an integer and an index and returns a boolean.
|
| nth:prime-nth(n) | → | integer |
| n | integer |
The index of the term to generate.
|
| nth:prime?(n) | → | boolean |
| n | integer |
The number to check.
|
| nth:recaman-seq(length) | → | Array<integer> |
| length | integer |
The length of the sequence to generate.
|
| nth:recaman-take-while(takeWhile) | → | Array<integer> |
| takeWhile | function |
A function that takes an integer and an index and returns a boolean.
|
| nth:recaman-nth(n) | → | integer |
| n | integer |
The index of the term to generate.
|
| nth:recaman?(n) | → | boolean |
| n | integer |
The number to check.
|
| length | integer |
The length of the sequence to generate. If not provided, the default is 6 (the maximum length of the pre-calculated Sylvester numbers).
|
| nth:sylvester-take-while(takeWhile) | → | Array<integer> |
| takeWhile | function |
A function that takes an integer and an index and returns a boolean.
|
| nth:sylvester-nth(n) | → | integer |
| n | integer |
The index of the term to generate.
|
| nth:sylvester?(n) | → | boolean |
| n | integer |
The number to check.
|
| nth:thue-morse-seq(length) | → | Array<integer> |
| length | integer |
The length of the sequence to generate.
|
| nth:thue-morse-take-while(takeWhile) | → | Array<integer> |
| takeWhile | function |
A function that takes an integer and an index and returns a boolean.
|
| nth:thue-morse-nth(n) | → | integer |
| n | integer |
The index of the term in the sequence.
|
| nth:thue-morse?(n) | → | boolean |
| n | integer |
The number to check.
|
| nth:tribonacci-seq(length) | → | Array<integer> |
| length | integer |
The length of the sequence to generate.
|
| nth:tribonacci-take-while(takeWhile) | → | Array<integer> |
| takeWhile | function |
A function that takes an integer and an index and returns a boolean.
|
| nth:tribonacci-nth(n) | → | integer |
| n | integer |
The index of the term to generate.
|
| nth:tribonacci?(n) | → | boolean |
| n | integer |
The number to check.
|
| a nth:count-combinations b | → | integer |
| nth:count-combinations(a, b) | → | integer |
| a nth:binomial b | → | integer |
| nth:binomial(a, b) | → | integer |
| set | Array<array> |
The input collection to generate combinations from.
|
| n | integer |
The size of each combination.
|
| a | array | |
| b | integer |
| nth:count-derangements(n) | → | integer |
| n | integer |
The total number of items.
|
| nth:derangements(set) | → | Array<array> |
| set | Array<array> |
The input collection to generate derangements from.
|
| nth:divisors(n) | → | Array<integer> |
| n | integer |
The number to find divisors for.
|
| nth:count-divisors(n) | → | integer |
| n | integer |
The number to count divisors for.
|
| nth:proper-divisors(n) | → | Array<integer> |
| n | integer |
The number to find proper divisors for.
|
| nth:count-proper-divisors(n) | → | integer |
| n | integer |
The number to count proper divisors for.
|
| n | integer |
The number to calculate the factorial for.
|
| nth:partitions(n) | → | Array<array> |
| n | integer |
The number to partition.
|
| nth:count-partitions(n) | → | integer |
| n | integer |
The number to count partitions for.
|
| nth:permutations(set) | → | Array<array> |
| set | Array<array> |
The input collection to generate permutations from.
|
| nth:power-set(set) | → | Array<array> |
| set | Array<any> |
The input collection to generate the power set from.
|
| nth:count-power-set(n) | → | integer |
| n | integer |
The size of the set.
|
| nth:prime-factors(n) | → | Array<integer> |
| n | integer |
The number to factor.
|
| nth:count-prime-factors(n) | → | integer |
| n | integer |
The number to count prime factors for.
|
| nth:distinct-prime-factors(n) | → | Array<integer> |
| n | integer |
The number to find distinct prime factors for.
|
| nth:count-distinct-prime-factors(n) | → | integer |
| n | integer |
The number to count distinct prime factors for.
|
| nth:multinomial(...args) | → | integer |
| args | Array<integer> |
The numbers representing the sizes of each group.
|
| nth:euler-totient(n) | → | integer |
| n | integer |
The number to calculate the totient for.
|
| nth:mobius(n) | → | integer |
| n | integer |
The number to calculate the Möbius function for.
|
| nth:mertens(n) | → | integer |
| n | integer |
The number to calculate the Mertens function for.
|
| nth:sigma(n) | → | integer |
| n | integer |
The number to calculate the sum of divisors for.
|
| nth:carmichael-lambda(n) | → | integer |
| n | integer |
The number to calculate the Carmichael function for.
|
| sets | Array<any> |
The input collections to calculate the Cartesian product from.
|
| nth:perfect-power(n) | → | Array<array> |
| n | integer |
The number to check.
|
| nth:mod-exp(base, exponent, modulus) | → | integer |
| remainders | Array<integer> |
The remainders of the congruences.
|
| moduli | Array<integer> |
The moduli of the congruences.
|
| values | Array<any> |
| kvps | Array<any> |
key - value pairs, where key is a string
|
If all expressions evaluate to truthy values, the value of the last expression is returned.
If all expressions evaluate to falsy values, the value of the last expression is returned.
| let s := value; |
| s | symbol |
The name of the variable to bind.
|
| value | any |
The value to bind to the variable.
|
| function name(...arg, ...let-binding) body end; |
| name | symbol |
The name of the function.
|
| arg | [...]arg-name [:= value] |
Arguments of the function.
|
| ... | rest-symbol |
Optional. The rest argument of the function.
|
| arg-name | symbol |
The name of the argument.
|
| value | any |
Optional. The default value of the argument.
|
| let-binding | symbol |
Optional. The let bindings of the function.
|
| body | one or more expressions |
The body of the function.
|
| try try-body catch catch-body end |
| try try-body catch(error) catch-body end |
| try-body | expressions |
The expressions to try.
|
| error | symbol |
The error variable to bind.
|
| catch-body | expression |
The expressions to evaluate if the try-body throws an error.
|
| throw(expr) | → | never |
| expr | any |
| if test then-body else else-body end |
| if test then-body end |
| test | expression |
The condition to test.
|
| then-body | expressions |
The expressions to evaluate if the test is truthy.
|
| else-body | expressions |
The expressions to evaluate if the test is falsy.
|
| unless test then-body else else-body end |
| unless test then-body end |
| test | expression |
The condition to test.
|
| then-body | expressions |
The expressions to evaluate if the test is falsy.
|
| else-body | expressions |
The expressions to evaluate if the test is truthy.
|
| cond cond-branch cond-branch ... end |
| cond-branch | case test then body |
A branch of the cond expression.
|
| test | expression |
The condition to test.
|
| body | expressions |
The expressions to evaluate if the test is truthy.
|
| switch value switch-branch switch-branch ... end |
| value | any |
The value to test.
|
| switch-branch | case test then body |
A branch of the switch expression.
|
| test | expression |
The condition to test.
|
| body | expressions |
The expressions to evaluate if the test is truthy.
|
| do body end |
| body | expressions |
The expressions to evaluate.
|
| recur(...recur-args) |
You can reference the first argument using either $1 or $. However, please note that $1 and $ are mutually exclusive and cannot be used simultaneously. E.g. #(* $ $1) is not valid.